package com.framework.controller;

import com.framework.entity.ter.TerTerminalInfo;
import com.framework.entity.ter.TerTerminalType;
import com.framework.exception.util.RespResult;
import com.framework.service.TerminalInfoService;
import com.framework.service.TerminalTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 功能描述: 终端信息控制器
 *
 * @author ck
 * @date 2018/9/11 15:12
 */
@RestController
@Api(value="终端信息模块",tags={"终端信息模块"})
@RequestMapping(value = "terminal")
public class TerminalController {

	@Autowired
	private TerminalInfoService terminalService;
	@Autowired
	private TerminalTypeService terminalTypeService;


	/**
	 * 机具归属查询
	 * @param token 当前登录人token
	 * @param sn 机具sn号
	 * @return
	 */
	@GetMapping("user/queryOwnTerminal")
	@ApiOperation("机具归属查询")
	@ApiImplicitParams({
			@ApiImplicitParam(name="sn",value="终端SN号",dataType="string", paramType = "query",required = true)
	})
	public RespResult queryOwnTerminal(String token,String sn) {
		Map<String,Object> map = terminalService.queryOwnMap(token,sn);
		return RespResult.ok(map);
	}

	/**
	 * 机具列表查询
	 * @param token 当前登录人token
	 * @param pageNo 分页
	 * @param startSn 开始终端号
	 * @param endSn 结束终端号
	 * @param model 类型
	 * @param isActivation 是否激活
	 * @return
	 */
	@GetMapping("user/queryTerminalList")
	@ApiOperation("自己的机具查询列表")
	@ApiImplicitParams({
			@ApiImplicitParam(name="pageNo",value="分页页码 0:第一页 依次叠加",dataType="int", paramType = "query"),
			@ApiImplicitParam(name="startSn",value="开始终端SN",dataType="string", paramType = "query"),
			@ApiImplicitParam(name="endSn",value="结束终端SN",dataType="string", paramType = "query"),
			@ApiImplicitParam(name="model",value="终端类型",dataType="string", paramType = "query"),
			@ApiImplicitParam(name="isActivation",value="是否激活 1：未激活 2：已激活 3：禁用",dataType="int", paramType = "query")})
	public RespResult queryTerminalList(String token,Integer pageNo,String startSn,String endSn,String model,Integer isActivation) {
		Map<String,Object> map = terminalService.queryTerminalList(token,pageNo,startSn,endSn,model,isActivation);
		return RespResult.ok(map);
	}

	/**
	 *  根据终端类型查询终端数据
	 * @param token 终端token
	 * @param terminalType 终端类型
	 * @return
	 */
	@GetMapping("queryTerByTypeList")
	@ApiOperation("根据终端类型查询终端数据")
	@ApiImplicitParams({
			@ApiImplicitParam(name="terminalType",value="终端类型",dataType="int", paramType = "query",required = true),
			@ApiImplicitParam(name="isActivation",value="终端状态 1：未激活 2：已激活",dataType="int", paramType = "query")
	})
	public RespResult queryTerminalByTypeList(String token,Integer terminalType,Integer isActivation) {
		List<TerTerminalInfo> list = terminalService.queryTerminalByTypeList(terminalType,token,isActivation);
		return RespResult.ok().put("terminalList",list);
	}

	/**
	 * 代理商的终端类型数量汇总
	 * @param token
	 * @return
	 */
	@GetMapping("user/queryTerTypeCount")
	@ApiOperation("代理商的终端类型数量汇总")
	@ApiImplicitParams({
			@ApiImplicitParam(name="isActivation",value="终端状态 1：未激活 2：已激活",dataType="int", paramType = "query"),
	})
	public RespResult queryTerminalTypeCountMap(String token,Integer isActivation) {
		Map<String,Object> map = terminalService.queryTerminalTypeCountMap(token,isActivation);
		return RespResult.ok(map);
	}

	/**
	 * 根据token查询机具类型list
	 * @param token 登录人token
	 * @return
	 */
	@GetMapping("user/queryTerminalTypeList")
	@ApiOperation("根据token查询机具类型")
	public RespResult queryTerminalTypeList(String token) {
		List<TerTerminalType> list = terminalTypeService.queryTerminalTypeByTokenList(token);
		return RespResult.ok().put("typeList",list);
	}

	/**
	 * 分配终端信息
	 * @param token 登录人token
	 * @param startSn 开始终端号
	 * @param endSn 结束终端号
	 * @return
	 */
	@PostMapping("user/disTerminal")
	@ApiOperation("分配终端")
	@ApiImplicitParams({
			@ApiImplicitParam(name="acceptId",value="接收人代理商id",dataType="int", paramType = "query"),
			@ApiImplicitParam(name="startSn",value="开始终端号",dataType="string", paramType = "query"),
			@ApiImplicitParam(name="endSn",value="结束终端号",dataType="string", paramType = "query"),
			@ApiImplicitParam(name="model",value="终端型号",dataType="string", paramType = "query"),
			@ApiImplicitParam(name="isActivation",value="1：未激活 2：已激活 3：禁用",dataType="int", paramType = "query"),
	})
	public RespResult disTerminal(String token,Long acceptId,String startSn,String endSn,String model,Integer isActivation) {
		terminalService.disTerminal( token, acceptId, startSn, endSn, model, isActivation);
		return RespResult.ok();
	}

	/**
	 *根据token查询机具型号
	 * @param token
	 * @return
	 */
	@GetMapping("user/queryTerminalModelList")
	@ApiOperation("根据token查询机具型号")
	public RespResult queryTerminalModelList(String token) {
		List<Map<String,Object>> list = terminalTypeService.queryTerminalModelList(token);
		return RespResult.ok().put("modelList",list);
	}
}
